package com.ax.api.route.business.prescription;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.ax.api.route.util.RouteConfig;

@RestController
@RequestMapping("/prescription")
public class PrescriptionRoute {
	@Autowired
    LoadBalancerClient loadBalancerClient;
    @Autowired
    RestTemplate restTemplate;
    
    /**
	 * queryPrescription
	 * remote_bussiness
	 * 查看个人处方详情(或全部)
	 */   
	@GetMapping("/queryPrescription")
	public String insertHemp(@RequestParam Map<String,Object> map){
		String value = "?prescriptionId={prescriptionId}&subjectCode={subjectCode}&doctorId={doctorId}&offset={offset}&limit={limit}";
		String url = geturl("/queryPrescription")+value;
		return restTemplate.getForObject(url,String.class,map);
		
  }
	/**
	 * insertPrescription
	 * remote_bussiness
	 * 新增处方(模块:(新增(处方审核信息))会员(*会员头像的截取),摄像头视频录制保存)
	 */   
	@GetMapping("/insertPrescription")
	public String insertPrescription(@RequestParam Map<String,Object> map){
		String value = "?associatorName={associatorName}&phone={phone}&personId={personId}&sex={sex}&birth={birth}&address={address}&remarks={remarks}&drugstoreId={drugstoreId}&drugstoreName={drugstoreName}&flag={flag}";
		value += "&prescriptionSeq={prescriptionSeq}&associatorId={associatorId}&associatorName={associatorName}&personId={personId}&age={age}&sex={sex}&subjectCode={subjectCode}&subjectName={subjectName}&patientPhone={patientPhone}&address={address}&anaphylaxis={anaphylaxis}&diagnosis={diagnosis}&prescriptionTime={prescriptionTime}&pharmacistAuditResult={pharmacistAuditResult}&pharmacistId={pharmacistId}&pharmacistName={pharmacistName}&drugstoreId={drugstoreId}&drugstoreName={drugstoreName}&remarks={remarks}&score={score}&isBuy={isBuy}";
		String url = geturl("/insertPrescription")+value;
		return restTemplate.getForObject(url,String.class,map);
		
  }
	/**
	 * queryPrescriptionAuditing
	 * remote_bussiness
	 * 查看处方审核详情(或全部)
	 */   
	@GetMapping("/queryPrescriptionAuditing")
	public String queryPrescriptionAuditing(@RequestParam Map<String,Object> map){
		String value = "?prescriptionAuditId={prescriptionAuditId}&AssociatorId={AssociatorId}&pharmacistId={pharmacistId}&offset={offset}&offset={offset}&limit={limit}";
		String url = geturl("/queryPrescriptionAuditing")+value;
		return restTemplate.getForObject(url,String.class,map);
		
  }
  /**
	 * insertOrUpdateAuditing
	 * remote_bussiness
	 * 处方审核(模块:药师审核处方(分两种1.本系统医师所开处方2.非本系统医师所开处方))
	 */   
	@GetMapping("/insertOrUpdateAuditing")
	public String insertOrUpdateAuditing(@RequestParam Map<String,Object> map){
		String value = "?associatorName={associatorName}&phone={phone}&personId={personId}&sex={sex}&birth={birth}&address={address}&remarks={remarks}&drugstoreId={drugstoreId}&drugstoreName={drugstoreName}&flag={flag}";
		value += "&prescriptionSeq={prescriptionSeq}&associatorName={associatorName}&personId={personId}&age={age}&sex={sex}&subjectCode={subjectCode}&subjectName={subjectName}&patientPhone={patientPhone}&address={address}&anaphylaxis={anaphylaxis}&diagnosis={diagnosis}&prescriptionTime={prescriptionTime}&pharmacistAuditResult={pharmacistAuditResult}&drugstoreName={drugstoreName}&drugstoreId={drugstoreId}&remarks={remarks}&score={score}&flag={flag}&isBuy={isBuy}";
		String url = geturl("/insertOrUpdateAuditing")+value;
		return restTemplate.getForObject(url,String.class,map);
		
}
	private String geturl(String path){
		 ServiceInstance serviceInstance = loadBalancerClient.choose(RouteConfig.BUSSINESS_ROUTE);
		 StringBuffer bf = new StringBuffer("http://");
		 bf.append(serviceInstance.getHost());
		 bf.append(":");
		 bf.append(serviceInstance.getPort());
		 bf.append(path);
		 return bf.toString();
		   
	   }
}
